package com.example.controller.admin;


import com.example.entity.StoreShoppingCart;
import com.example.result.Result;
import com.example.service.StoreShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 1. @ClassDescription:
 * 2. @author: Z
 * 3. @date: 2024年03月21日 23:02
 */
@RestController
@RequestMapping("/admin/storeShoppingCart")
@Slf4j
@Api(tags = "购物车接口")
public class StoreShoppingCartController {

    @Autowired
    private StoreShoppingCartService shoppingCartService;

    @PostMapping()
    @ApiOperation("购物车添加商品")
    public Result add(@RequestBody StoreShoppingCart shoppingCart){
        log.info("购物车添加商品：{}",shoppingCart);
        Result result = shoppingCartService.add(shoppingCart);
        return result;
    }

    @GetMapping("/list/{storeId}")
    @ApiOperation("查看购物车")
    public Result<List<StoreShoppingCart>> list(@PathVariable Long storeId){
        log.info("查询购物车:{}",storeId);
        List<StoreShoppingCart> list = shoppingCartService.showShoppingCart(storeId);
        return Result.success(list);
    }

    @DeleteMapping("/clean/{storeId}")
    @ApiOperation("清空购物车")
    public Result cleanShoppingCart(@PathVariable Long storeId){
        Result result = shoppingCartService.cleanShoppingCart(storeId);
        return result;
    }

    @PostMapping("/sub")
    @ApiOperation("删除购物车中一个商品")
    public Result sub(@RequestBody StoreShoppingCart storeShoppingCart){
        log.info("删除单个商品:{}",storeShoppingCart);
        Result result = shoppingCartService.sub(storeShoppingCart);
        return result;
    }
}
